@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-md-offset-0">
                <div class="panel panel-default">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            表情包详情
                            <a href="/smile">返回</a>
                            <button onclick="preone()">上一张</button>
                            <button onclick="nextone()">下一张</button>
                        </div>
                        <div class="panel-body">
                            <input id="id" type="number" value="{{ $id }}" hidden>
                            <div><img src="/images/smile/{{ $url }}" alt=""></div>
                            <div>文件名：<br>{{ $url }}</div>
                            <div>重命名：<input style="width:100%" type="text" id="newName" value="{{ $url }}"> <input onclick="rebut()" id="rebu" type="button" value="提交"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var id = 0;
        var url = '';
        function rebut() {
            id = parseInt($('#id').val());
            url = $('#newName').val();
            $.ajax({
                url: "api/newSmileName",
                type:"POST",
                datatype:"json",
                data:{id:id,url:url},
                success: function(data){
                    id = id+1;
                    var r_url = '/smileDetail?id='+id;
                    window.location.href=r_url;
                },
                error:function(e){
                    alert('修改失败！')
                }
            });
        }
        function nextone() {
            id = parseInt($('#id').val());
            id = id+1;
            var r_url = '/smileDetail?id='+id;
            window.location.href=r_url;
        }
        function preone() {
            id = parseInt($('#id').val());
            if(id>1){
                id = id-1;
            }
            var r_url = '/smileDetail?id='+id;
            window.location.href=r_url;
        }
    </script>
@endsection
